package com.vinobase.model.bean;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Cached;
import com.googlecode.objectify.annotation.Entity;

import javax.persistence.Id;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

@Entity
@Cached
public class CountryLocal implements Comparable{

    @Id
    private Long countryId;


    private Key<Country> country;


    private Key<Culture> culture;

    @NotNull
	@Size(min=1, max=25)
    private String name;




    public Long getCountryId() {
        return countryId;
    }

    public void setCountryId(Long countryId) {
        this.countryId = countryId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public Key<Culture> getCulture() {
        return culture;
    }

    public void setCulture(Key<Culture> culture) {
        this.culture = culture;
    }

    public Key<Country> getCountry() {
        return country;
    }

    public void setCountry(Key<Country> country) {
        this.country = country;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        CountryLocal that = (CountryLocal) o;

        if (countryId != null ? !countryId.equals(that.countryId) : that.countryId != null) return false;
        if (culture != null ? !culture.equals(that.culture) : that.culture != null) return false;
        if (name != null ? !name.equals(that.name) : that.name != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = countryId != null ? countryId.hashCode() : 0;
        result = 31 * result + (culture != null ? culture.hashCode() : 0);
        result = 31 * result + (name != null ? name.hashCode() : 0);
        return result;
    }

    public int compareTo(Object o) {
         if(!(o instanceof CountryLocal)){
            return -9999;
        }
        CountryLocal c = (CountryLocal)o;
        int cmp =  name.compareTo(c.getName());
        if(cmp==0)
            cmp = countryId.compareTo(c.getCountryId()) ;
        return cmp;
    }
}
